/*    
 * Copyright (c) 2013 ISoftStone, Inc.
 * All right reserved.
 *
 * 文件名：      IBillDao.java
 * 作者:     Jacky Wang
 * 创建日期： 2013-7-29 下午03:31:48
 * 版本：           
 *
 */
package com.isoftstone.industry.aaa.core.dao.assist;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.isoftstone.industry.persistance.bean.Bill;
import com.isoftstone.modules.core.persistence.IGenericDao;

/**
 *
 * @author jacky
 */
public interface BillDao extends IGenericDao<Bill, String>
{
	@Query("select x from Bill x where x.user.id=?1 and x.billingCycle.id=?2")
	Bill findByUserAndCycle(String userId, String cycleId);
	
	@Modifying
	@Query("update Bill x set x.deliverStatus=:status, x.deliverTime=:time where x.id=:id")
	void updateDeliverStatus(@Param("id")String billId, @Param("status")String status, @Param("time")Timestamp statusTime);
	
	@Query("select x from Bill x where x.user.id=?1 and x.payableAmount>0")
	List<Bill> findByUserAndPayableGreaterThan0(String userId);
	
	@Query("select count(*) from Bill x where x.user.id=?1 and x.billingCycle.id=?2")
	long countByUserAndCycle(String userId, String cycleId);
}
